package cn.iocoder.yudao.module.crossborder.order.service.orderstatuslog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.order.controller.admin.orderstatuslog.vo.*;
import cn.iocoder.yudao.module.crossborder.order.dal.dataobject.orderstatuslog.OrderStatusLogDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.order.dal.mysql.orderstatuslog.OrderStatusLogMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.order.enums.ErrorCodeConstants.*;

/**
 * 跨境电商订单状态流转 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class OrderStatusLogServiceImpl implements OrderStatusLogService {

    @Resource
    private OrderStatusLogMapper orderStatusLogMapper;

    @Override
    public Long createOrderStatusLog(OrderStatusLogSaveReqVO createReqVO) {
        // 插入
        OrderStatusLogDO orderStatusLog = BeanUtils.toBean(createReqVO, OrderStatusLogDO.class);
        orderStatusLogMapper.insert(orderStatusLog);

        // 返回
        return orderStatusLog.getId();
    }

    @Override
    public void updateOrderStatusLog(OrderStatusLogSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderStatusLogExists(updateReqVO.getId());
        // 更新
        OrderStatusLogDO updateObj = BeanUtils.toBean(updateReqVO, OrderStatusLogDO.class);
        orderStatusLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderStatusLog(Long id) {
        // 校验存在
        validateOrderStatusLogExists(id);
        // 删除
        orderStatusLogMapper.deleteById(id);
    }

    @Override
        public void deleteOrderStatusLogListByIds(List<Long> ids) {
        // 删除
        orderStatusLogMapper.deleteByIds(ids);
        }


    private void validateOrderStatusLogExists(Long id) {
        if (orderStatusLogMapper.selectById(id) == null) {
            throw exception(ORDER_STATUS_LOG_NOT_EXISTS);
        }
    }

    @Override
    public OrderStatusLogDO getOrderStatusLog(Long id) {
        return orderStatusLogMapper.selectById(id);
    }

    @Override
    public PageResult<OrderStatusLogDO> getOrderStatusLogPage(OrderStatusLogPageReqVO pageReqVO) {
        return orderStatusLogMapper.selectPage(pageReqVO);
    }

}